mui.init({
	swipeBack: true,
	pullRefresh: {
		container: "#refreshContainer",
		down: {
			style: 'circle',
			color: '#2DB009',
			height: '50px',
			range: '100px',
			offset: '0px',
			auto: false,
			callback: function () {
				index_data.gemodule();
				setTimeout(function() {
					mui("#refreshContainer").pullRefresh().endPulldownToRefresh(false);
				}, 1000);
			}
		}
	}
});
var flag = false;
var index_data = null;

mui.plusReady(function() {
	hideScrollBar();
	index_data = new Vue({
		el: '#goods_VUE',
		data: {
			category_list: [],
			cateid: '',
			goods_list: [],
			goods_list1: [],
			goods_list2: [],
			goods_list3: [],
			goods_list4: [],
			tabIndex: 0,
			dataId: '',
			category_product: [],
			category_title: [],
			auditStatus:'no',
		},
		mounted() {
			var self = this;
			this.gemodule();
			this.$nextTick(function() {
				self.auditStatus = plus.storage.getItem('auditStatus') ? plus.storage.getItem('auditStatus') : 'no';
			})
		},
		methods: {
			gemodule:function(){
				var api_host = plus.storage.getItem('HOST_URL');
				var self = this;
				mui.getJSON("../../../manifest.json",null,function(data) {
					mui.ajax({
						url: api_host + '/api/other/other/getAppModule',
						dataType: 'json',
						data: {
							'versionNum': data.version.code,
						},
						type: 'get',
						timeout: 3000,
						success: function (msg) {
							if (msg.code == 1) {
								if (msg.data.search == 0) {
									$('.icon_top_sr').css('display', 'none');
								} else {
									$('.icon_top_sr').css('display', 'block');
								}
							}
							self.get_category_product();
						},
						error: function (xhr, type, errorThrown) {
							self.get_category_product();
						}
					});
				})
			},
			get_category_product: function() {
				showWatting();
				var api_host = plus.storage.getItem('HOST_URL');
				mui.ajax({
					url: api_host + '/api/shop/category/getCategoryAndProductsV116',
					dataType: 'json',
					type: 'get',
					success: function(msg) {
						if (msg.code == 1) {
							index_data.category_product = msg.data;
							if (typeof(msg.data[0]) != "undefined") {
								if (msg.data[0].goods == false) {
									index_data.goods_list1 = null;
								} else {
									index_data.goods_list1 = msg.data[0].goods;
								}
							}
							if (typeof(msg.data[1]) != "undefined") {
								if (msg.data[1].goods == false) {
									index_data.goods_list2 = null;
								} else {
									index_data.goods_list2 = msg.data[1].goods;
								}
							}

							if (typeof(msg.data[2]) != "undefined") {
								if (msg.data[2].goods == false) {
									index_data.goods_list3 = null;
								} else {
									index_data.goods_list3 = msg.data[2].goods;
								}
							}

							if (typeof(msg.data[3]) != "undefined") {
								if (msg.data[3].goods == false) {
									index_data.goods_list4 = null;
								} else {
									index_data.goods_list4 = msg.data[3].goods;
								}
							}
						}
					},
					error: function() {
						mui.toast('加载失败!', {
							duration: '200',
							type: 'div'
						});
					},
					complete: function() {
						plus.nativeUI.closeWaiting();
						mui("#refreshContainer").pullRefresh().endPulldownToRefresh(false);
					}
				})
			},


			select_tab: function(e) {
				this.tabIndex = e.target.getAttribute('tab-index');
			},

			open_detail: function(id) {
				mui.openWindow({
					url: '../courseDetail/mallDetail.html',
					extras: {
						'product_id': id
					},
					createNew: false,
					show: {
						autoShow: true,
						aniShow: 'pop-in',
						duration: 400
					},
					waiting: {
						autoShow: false,
					}
				});
			},
		},
		computed: {
			show_content1: function() {
				if (this.tabIndex == 0) {
					return {
						'display': 'block'
					};
				} else {
					return {
						'display': 'none'
					};
				}
			},
			show_content2: function() {
				if (this.tabIndex == 1) {
					return {
						'display': 'block'
					};
				} else {
					return {
						'display': 'none'
					};
				}
			},
			show_content3: function() {
				if (this.tabIndex == 2) {
					return {
						'display': 'block'
					};
				} else {
					return {
						'display': 'none'
					};
				}
			},
			show_content4: function() {
				if (this.tabIndex == 3) {
					return {
						'display': 'block'
					};
				} else {
					return {
						'display': 'none'
					};
				}
			}
		}
	})
})

document.querySelector('.icon_top_sr').addEventListener('tap', function() {
	mui.openWindow({
		url: '../search/keywords.html',
		createNew: false,
		show: {
			autoShow: true,
			aniShow: 'slide-in-top',
			duration: 100
		},
		waiting: {
			autoShow: false,
		}
	})
});